﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Plumbing;
using Autodesk.Revit.UI;
using YArchitech.Revit;
using YRevitJig;

namespace YArchitech.Plumbing
{
	public class MultiRiserPipesLinesJig : RiserPipeLinesJig
	{
		public List<Pipe> RiserPipes { get; set; }

		public List<RiserPipeAndCenter> RiserPipePoints { get; set; }

		public MultiRiserPipesLinesJig(UIDocument uiDoc, FrmMarkRiserpipe form) : base(uiDoc, form)
		{
			this.RiserPipePoints = new List<RiserPipeAndCenter>();
		}

		public override void Draw(PaintEventArgs paintEventArgs)
		{
			base.Draw(paintEventArgs);
			int count = this.RiserPipePoints.Count;
			if (!this.m_ptCur.IsEmpty && paintEventArgs != null && count > 1)
			{
				try
				{
					base.UpdateData();
					double textLength = UnifiedModified.GetTextLength(this.formData.checkAreaNumber.Checked, this.formData.checkFloorNumber.Checked);
					this.resultLines.Clear();
					XYZ xyz = base.Client2Revit(this.m_ptCur);
					XYZ xyz2 = new XYZ(xyz.X, xyz.Y, this.RiserPipePoints[0].Location.Z);
					List<RiserPipeAndCenter> list = new List<RiserPipeAndCenter>();
					List<RiserPipeAndCenter> list2 = MarkRiserPipeUtility.SortPoints(this.RiserPipePoints, xyz2);
					XYZ markVector = list2[count - 1].Location - list2[0].Location;
					XYZ xyz3 = null;
					XYZ xyz4 = new XYZ();
					this.resultLines = MarkRiserPipeUtility.DrawMultiPipesMarkLines(list2, xyz2, markVector, textLength, ref list, ref xyz3, ref xyz4, 0.0);
					XGraphics g = new XGraphics(paintEventArgs.Graphics, base.JigPen);
					foreach (Line curve in this.resultLines)
					{
						new XLine2D(base.Revit2Client(curve.GetEndPoint(0)), base.Revit2Client(curve.GetEndPoint(1))).Draw(g);
					}
				}
				catch (Exception ex)
				{
					ex.ToString();
				}
			}
		}

		public override List<Curve> CreateCurves()
		{
			List<Curve> list = new List<Curve>();
			foreach (Line item in this.resultLines)
			{
				list.Add(item);
			}
			return list;
		}
	}
}
